#!/usr/bin/env python
# encoding: utf-8
# @Time    : 2019/10/11 16:28
# @Author  : ZRD
# @Site    : 
# @File    : yaml.py
# @Software: PyCharm

import yaml

import os


def get_yaml_data(yaml_file):
    # 打开yaml文件
    print("***获取yaml文件数据***")
    file = open(yaml_file, 'r', encoding="utf-8")
    file_data = file.read()
    file.close()

    print(file_data)
    print("类型：", type(file_data))

    # 将字符串转化为字典或列表
    print("***转化yaml数据为字典或列表***")
    data = yaml.load(file_data)
    print(data)
    print("类型：", type(data))
    return data


def get_yaml_data2(filename):
    f = open(filename, 'r', encoding="utf-8")
    y = yaml.safe_load(f.read())
    print(y)


if __name__ == '__main__':
    current_path = os.path.abspath(".")
    yaml_path = os.path.join(current_path, "agent.yml")
    get_yaml_data2(yaml_path)
